package thread;
//join()的使用
public class ThreadDemo09 {
    public static void main(String[] args) throws InterruptedException {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                for(int i = 0; i < 5; i++){
                    System.out.println(Thread.currentThread().getName() + "：我正在工作！");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                System.out.println(Thread.currentThread().getName() + "：我工作完了！");
            }
        };

        Thread t1 = new Thread(runnable, "李四");
        Thread t2 = new Thread(runnable, "王五");
        System.out.println(Thread.currentThread().getName() + "：让李四开始工作！");
        t1.start();
        t1.join();
        System.out.println(Thread.currentThread().getName() + "：李四工作结束了！");
        System.out.println(Thread.currentThread().getName() + "：让王五开始工作");
        t2.start();
        t2.join();
        System.out.println(Thread.currentThread().getName() + "：王五工作结束了！");


    }
}
